<template>
<el-container>
  <el-header style="height: auto;">
    <el-row>
      <el-col>
        <el-button type="primary" size="small" @click="toBack">返回</el-button>
      </el-col>
    </el-row>
    <el-form>
      <el-row>
        <el-col :xl="{ span: 6 }" :lg="{ span: 6 }">
          <el-form-item label="业务号码" label-width="80px" style="width: 95%;">
            <el-input size="small" v-model.trim="cardNumberSearch"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xl="{ span: 6 }" :lg="{ span: 6 }">
          <el-form-item label="卡体类型" label-width="80px">
            <el-select v-model="dictCardTypeSearch" placeholder="请选择卡体类型" style="width: 95%;" size="small">
              <el-option v-for="dictCardType in dictCardTypeSelect" :key="dictCardType.value" :label="dictCardType.label" :value="dictCardType.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-col class="export" :xl="{ span: 6 }" :lg="{ span: 6 }">
        <el-form-item>
          <el-button size="small" type="primary" @click="currentPage = 0 ; initData()">查询</el-button>
        </el-form-item>
      </el-col>
    </el-form>
  </el-header>
  <el-main>
    <el-table :header-cell-style="{ 'background':$store.state.app.tableBgColor,'color':'#606266' }" :data="tableData" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange" v-loading.fullscreen="" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.2)">
      <el-table-column type="selection" align="center"></el-table-column>
      <el-table-column prop="cardNumber" label="业务号码" align="center"></el-table-column>
      <el-table-column prop="dictCardTypeName" label="卡体类型" align="center"></el-table-column>
      <el-table-column prop="cardFlowTotal" label="充值流量" align="center"></el-table-column>
      <el-table-column prop="carFlowSurplus" label="剩余流量" align="center"></el-table-column>
      <el-table-column prop="cardFlowUsed" label="本月已用（虚量）" align="center"></el-table-column>
      <el-table-column prop="cardFlowActUsed" label="本月已用（实际）" align="center"></el-table-column>
      <el-table-column prop="name" label="操作" align="center">
        <template slot-scope="scope">
          <el-button @click="toEcharts(scope.row)">查看流量</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block"><span class="demonstration"></span>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="10" layout="prev, pager, next, jumper" :page-count="maxPage" :hide-on-single-page="value" background></el-pagination>
    </div>
  </el-main>
</el-container>
</template>

<script>
  import { userDataSelectCustomerCard } from '@/api/getData'


export default {
  name: 'Card',
  data() {
    return{
      customerId : 0,
      value: false,
      pageSize: 10,
      currentPage: 1,
      maxPage: 1,
      tableData : [],
      multipleSelection:[],
      cardNumberStart:"",
      cardNumberEnd:"",
      cardNumberSearch:"",
      dictCardTypeSearch:"",
      dictCardTypeSelect : [{
        value:"",
        label:"请选择"
      } , {
        value:"MP1SINGLE",
        label:"MP1单切大卡"
      } , {
        value:"MP2SINGLE",
        label:"MP2单切大卡"
      } , {
        value:"MP1DOUBLE",
        label:"MP1双切卡"
      } , {
        value:"MP2DOUBLE",
        label:"MP2双切卡"
      } , {
        value:"MP1TRIPLE",
        label:"MP1三切卡"
      } , {
        value:"MP2TRIPLE",
        label:"MP2三切卡"
      } , {
        value:"MP1MICRO",
        label:"MP1 Micro卡"
      } , {
        value:"MP2MICRO",
        label:"MP2 Micro卡"
      } , {
        value:"MP1NANO",
        label:"MP1 Nano卡"
      } , {
        value:"MP2NANO",
        label:"MP2 Nano卡"
      } , {
        value:"MS056",
        label:"MS0 5*6"
      } , {
        value:"MS156",
        label:"MS1 5*6"
      } , {
        value:"MS055",
        label:"MS0 5*5"
      } , {
        value:"MS155",
        label:"MS1 5*5"
      }]
    }
  },
  created () {
    this.customerId = this.$route.params.customerId
    this.initData();
  },
  methods: {

    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleSizeChange(val) {
      //console.log(`每页 ${val} 条`)
      this.pageSize = val
    },
    handleCurrentChange(val) {
      //console.log(`当前页: ${val}`)
      this.currentPage = val
      this.initData()
    },
    toEcharts(card) {
      this.$router.push({ path: '/user/echarts/'+card.id })
    },
    // 页面初始化
    async initData(theKey) {
      const returnData = await userDataSelectCustomerCard({
        customerId:this.customerId,
        dictCardType:this.dictCardTypeSearch,
        cardNumber:this.cardNumberSearch,
        page: {
          current: this.currentPage + '',
          size: this.pageSize + ''
        }
      }, {
        obj: this,
        key: 'tableLoading;' + theKey
      })
      this.tableData = []
      if (returnData._result) {
        this.maxPage = Math.ceil(returnData.data.total / this.pageSize) // 分页的最大页数
        // 数据回显
        returnData.data.records.map(item => {
          const obj = {}
          obj.id = item.id
          obj.cardNumber = item.cardNumber // 业务号码
          obj.cardUse = item.cardUse // 备注
          obj.dictCardTypeName = item.dictCardTypeName //卡体类型
          obj.cardFlowTotal = item.cardFlowTotal // 总量
          obj.carFlowSurplus = item.carFlowSurplus // 剩余用量
          obj.cardFlowUsed = item.cardFlowUsed // 使用流量（虚量）
          obj.cardFlowActUsed = item.cardFlowActUsed // 使用流量（实际）
          this.tableData.push(obj)
        })
        this.tableLoading = false
      }
    },
    toBack() {
      this.$router.back(-1)
    }
  }
}
</script>

<style scoped lang="scss">
.el-container {

  .el-header {
    margin-top: 5vh;

    .el-form {
      margin-top: 3vh;
      .el-row /deep/ label {
        text-align: left;
      }
    }

    .select /deep/ span {
      width: 14%;
    }

    .line {
      text-align: center;
    }
  }

  .el-main {
    .block {
      float: right;
    }
  }
}
.el-picker-panel.el-date-range-picker.el-popper {
  margin-left: 310px;
}

.app-wrapper.openSidebar {
  .select /deep/ span {
    width: 14%;
  }
}
.el-popper[x-placement^=top] {
  box-shadow: 0px 0px 10px #888888;
  margin-left: 6px;
  margin-right: -39px;
  button {
    display: block;
  }
  .operation {
    border: 0;
    outline: none;
    display: block;
    text-align: center;
    margin: 0;
  }
}
</style>
